/*
 * CourseColors.java
 *
 * Created on November 12, 2006, 11:14 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.umn.cs5115.scheduler.entities;

import edu.umn.cs5115.scheduler.framework.gui.AlphaColor;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Returns nice colors for courses.
 * @author grant
 */
public class CourseColors
{
    private static int nextColor = 0;
    public static AlphaColor GREEN = new AlphaColor(57, 191, 75);
    public static AlphaColor BLUE = new AlphaColor(72, 120, 207);
    public static AlphaColor RED = new AlphaColor(215, 88, 67);
    public static AlphaColor YELLOW = new AlphaColor(240, 253, 29);
    public static AlphaColor PINK = new AlphaColor(212, 98, 223);
    public static AlphaColor ORANGE = new AlphaColor(248, 176, 27);
    public static AlphaColor TEAL = new AlphaColor(94, 222, 203);
    public static AlphaColor GRAY = new AlphaColor(189, 189, 189);
    public static AlphaColor CRIMSON = new AlphaColor(178, 44, 39); // Too close to red!
    private static AlphaColor[] colors = new AlphaColor[]
    {
        GREEN,
        BLUE,
        RED,
        YELLOW,
        PINK,
        ORANGE,
        TEAL,
        GRAY
    };
    
    
    /**
     * Returns the least-recently returned color from the list of colors that
     * CourseColors knows about.
     * @return A nice looking color.
     */
    public static AlphaColor getNextColor()
    {
        int thisColor = nextColor;
        nextColor++;
        if (nextColor >= colors.length)
            nextColor = 0;
        return colors[thisColor];
    }
    
    /**
     * Returns the first available color not in the schedule of courses.
     * @return A nice looking color that isn't already used.
     */
    public static AlphaColor getUnusedColor(Schedule schedule)
    {
        Set courses = schedule.getCourses();
        Set availableColors = new HashSet();
        for(int i = 0; i < colors.length; i++)
            availableColors.add(colors[i]);
        Iterator iterator = courses.iterator();
        while(iterator.hasNext())
        {
            Course thisCourse = (Course) iterator.next();
            availableColors.remove(thisCourse.getColor());
        }
        AlphaColor theColor;
        if (availableColors.size() > 0)
        {
            do
            {
                theColor = getNextColor();
            } while (!availableColors.contains(theColor));
        } else {
            theColor = getNextColor();
        }
        return theColor;
    }
}
